<?php
/**
 * 
 * @author Paolo Bertuzzo
 *
 */
namespace User\Controller;

use Utilities\Session\SessionFacade;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Mvc\MvcEvent;

/**
 */
class AbstractAuthenticatedController extends AbstractActionController
{
    /**
     * (non-PHPdoc)
     * @see \Catalog\Controller\AbstractGeolocalizedController::onDispatch()
     */
    public function onDispatch(MvcEvent $e)
    {
       // Check if user is logged in
       $sessionFacade = new SessionFacade();

       if (is_null($sessionFacade->getCustomer())) {
           // Get the current url
           $url = $e->getRequest()->getUriString();
           
           // Redirect user to login page
           return $this->redirect()->toRoute('user', array('controller' => 'authentication', 'action' => 'authenticate'), 
               array('query' => array('url' => $url)), true);
       }
           
       parent::onDispatch($e);
    }
    
}

?>